package com.mmg.cosplay.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mmg.cosplay.entity.R;
import com.mmg.cosplay.entity.dto.RolePresetRequestDTO;
import com.mmg.cosplay.entity.po.RolePreset;
import com.mmg.cosplay.service.IRolePresetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色预设相关接口
 * @author fly
 * @since 2025-09-23
 */
@Tag(name = "角色预设相关接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/role-preset")
public class RolePresetController {

    private final IRolePresetService rolePresetService;

    /**
     * 获取角色预设分页列表
     */
    @Operation(summary = "获取角色预设分页列表")
    @GetMapping("/list")
    public ResponseEntity<Page<RolePreset>> list(RolePresetRequestDTO requestDTO) {
        return R.success(rolePresetService.listByDTO(requestDTO));
    }

    /**
     * 根据ID获取角色预设
     */
    @Operation(summary = "根据ID获取角色预设")
    @GetMapping("/find/{id}")
    public ResponseEntity<RolePreset> findById(@PathVariable("id") String id) {
        RolePreset rolePreset = rolePresetService.getById(id);
        return R.success(rolePreset);
    }

    /**
     * 创建新的角色预设
     */
    @Operation(summary = "创建新的角色预设")
    @PostMapping
    public ResponseEntity<RolePreset> create(@RequestBody RolePreset rolePreset) {
        Long loginId = Long.parseLong(StpUtil.getLoginId().toString());
        rolePreset.setCreateBy(loginId);
        rolePreset.setUpdateBy(loginId);
        rolePresetService.save(rolePreset);
        return R.success(rolePreset);
    }

    /**
     * 更新角色预设
     */
    @Operation(summary = "更新角色预设")
    @PutMapping
    public ResponseEntity<RolePreset> update(@RequestBody RolePreset rolePreset) {
        Long loginId = Long.parseLong(StpUtil.getLoginId().toString());
        rolePreset.setUpdateBy(loginId);
        rolePresetService.updateById(rolePreset);
        return R.success(rolePreset);
    }

    /**
     * 删除角色预设
     */
    @Operation(summary = "删除角色预设")
    @DeleteMapping("/{id}")
    public ResponseEntity<?> delete(@PathVariable("id") String id) {
        rolePresetService.removeById(id);
        return R.success(null);
    }

}
